package com.motionlog.adapter;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.motionlog.R;
import com.motionlog.model.Log;

public class HistoryAdapter extends BaseAdapter {

	private LayoutInflater mInflater;
	private List<Log> mLogs;

	public HistoryAdapter(Context context, List<Log> logs) {
		mInflater = LayoutInflater.from(context);
		mLogs = logs;
	}

	@Override
	public int getCount() {
		return mLogs.size();
	}

	@Override
	public Log getItem(int position) {
		return mLogs.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.history_list_item, null);
		}
		TextView time = (TextView) convertView.findViewById(R.id.time);
		TextView motion = (TextView) convertView.findViewById(R.id.motion);
		TextView level = (TextView) convertView.findViewById(R.id.level);
		TextView desc = (TextView) convertView.findViewById(R.id.desc);

		Log log = getItem(position);
		time.setText(SimpleDateFormat.getTimeInstance().format(
				new Date(log.datetime)));
		motion.setText(log.motion.name);
		level.setText(String.valueOf(log.level));
		desc.setText("");

		return convertView;
	}
}
